package validator

import "regexp"

type numberNoneZeroType struct{}

var numberNoneZeroRegexp = regexp.MustCompile("^[1-9][0-9]*$")

func (n *numberNoneZeroType) Validate(name string, val string, required bool) (bool, string) {
	if val == "" {
		if required {
			return false, name + "不能为空"
		}
		return true, ""
	}

	if !numberNoneZeroRegexp.MatchString(val) {
		return false, name + "应为非0的整数"
	}

	return true, ""
}
